package org.bet.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bet.dao.GenomeDao;
import org.bet.domain.Genome;
import org.bet.exception.BETException;
import org.bet.exception.BETExceptionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GenomeService {
	private final Log logger = LogFactory.getLog(getClass());
	
	@Autowired
	private BETExceptionFactory exceptionFactory;
	
	@Autowired
	private GenomeDao genomeDao;
	
	public void saveOrUpdateGenome(Genome genome) throws BETException {
		try{
			if(genome != null){				
				genomeDao.saveOrUpdateGenome(genome);
			}
		}
		catch(Exception e){
			logger.error(e);
			throw exceptionFactory.createException("error.genomeService.saveOrUpdate", new Object[]{ genome.getId() }, e);
			
		}
	}

	public boolean existsGenome(String id) throws BETException {
		try{
			
			return genomeDao.existsGenome(id);
		}
		catch(Exception e){
			logger.error(e);
			throw exceptionFactory.createException("error.genomeService.saveOrUpdate", new Object[]{ id }, e);
			
		}
	}

	public Genome getGenome(String id) throws BETException {
		try{
			
			return genomeDao.getGenome(id);
		}
		catch(Exception e){
			logger.error(e);
			throw exceptionFactory.createException("error.genomeService.saveOrUpdate", new Object[]{ id }, e);
			
		}
	}

}
